<template>
	<view class="container">
		<u-navbar :is-fixed="false" :border-bottom="false" :is-back="false" back-icon-name="arrow-leftward" title="登录"
			:background="{ background: '#fff' }" title-color="#000000">

		</u-navbar>

		<view class="form">
			<u-form :model="form" ref="uForm" >
				<view class="test">
					<u-form-item :rightIconStyle="{color: '#888', fontSize: '32rpx'}" right-icon="none"
						 label="" prop="phone" label-width="150" >
						<u-input  placeholder="请输入用户名" v-model="form.username" type="text" ></u-input>
					</u-form-item>
          <u-form-item :rightIconStyle="{color: '#888', fontSize: '32rpx'}" right-icon="none"
						 label="" prop="phone" label-width="150" >
						<u-input  placeholder="请输入密码" v-model="form.password" type="text" ></u-input>
					</u-form-item>
				</view>
			</u-form>
			<u-button shape="circle" :ripple="true" ripple-bg-color="#909399" :custom-style="customStyle1" @click="submit">登录</u-button>

		</view>
		<view class="content">
				<navigator url="/pages/account/register" hover-class="none" class="change">没有账号？点击注册</navigator>
		</view>
		<!--  -->
	</view>
</template>

<script>
	import {
		mapState,
		mapGetters,
		mapMutations,
		mapActions
	} from 'vuex'
	export default {
		computed:{
			...mapState('user', ['isLogin']),
		},
		data() {
			return {
				form:{
					username:'wangqian88',
					password: 'wangqian2020'
				},
				customStyle1:{
          margin:'20rpx 0',
          fontWeight: 'bold',
          color: '#FFFFFF',
          background:'#1488FF'
        },

				disabled: false
			};
		},
		onload() {
			console.log('login onload',uni.getStorageSync('accessToken'))
		},
		mounted(){
			console.log('mounted',uni.getStorageSync('accessToken'))
		},
		methods: {
			...mapMutations('user', ['setUserInfo','setAccessToken','setIsLogin']),
			submit() {
				let data = {
					username: this.form.username,
					password: this.form.password
				}
				uni.setStorageSync('accessToken','')
        let accessToken = uni.getStorageSync('accessToken');
        console.log('access', accessToken)
        this.$http.post('api/v2/login', data).then(res => {
          console.log('登录成功', res)
					this.$u.func.login(res)
          /* this.setUserInfo(res)
					this.setAccessToken(res.token)
					this.setIsLogin(true)
          uni.switchTab({
						url: '/pages/coin/index'
					}) */
        }).catch(err => {
					console.log(err)
					this.$u.func.showToast({
						title: '用户名或密码错误',
					})
				})

			},
			handleInputCheck() {
				this.disabled = false
			},
		}
	};
</script>

<style lang="scss">
	.container {
		min-height: 100vh;
		overflow: hidden;
		.form {
				padding: 30rpx;
		}
		.content {
			width: 100vw;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: bold;
			color: #1488FF;
		}
	}

	
</style>
